package com.zofer.study.num;

/**
 * @description 数字反转
 * @date: 2020/10/19 10:34
 */
public class NumReverse {

    public static void main(String[] args) {
        reverse(1506200);
    }

    public static int reverse (int x) {
        // write code here
        if(x == 0){
            return 0;
        }
        int reserveNum = 0;
        while(x != 0){
            reserveNum = reserveNum*10 + x%10;
            x = x/10;
        }

        if(reserveNum < Integer.MIN_VALUE || reserveNum > Integer.MAX_VALUE){
            return 0;
        }
        return reserveNum;

    }
}
